{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "\n",
    "import glob\n",
    "import os\n",
    "import sys\n",
    "import json\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import tensorflow as tf\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import lib.dataset as dataset\n",
    "import lib.network as network\n",
    "import lib.utils as utils\n",
    "import lib.vis as vis\n",
    "from PIL import Image\n",
    "from collections import deque\n",
    "from tensorflow.python.tools import inspect_checkpoint\n",
    "from moviepy.editor import *\n",
    "params=utils.read_params()\n",
    "from tensorboard.backend.event_processing.event_accumulator import EventAccumulator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "models_remote=utils.list_folders(params[\"DIRS\"][\"MODELS_REMOTE\"])\n",
    "window_width=1\n",
    "\n",
    "raw_experiment_params=pd.DataFrame()\n",
    "raw_experiment_data=pd.DataFrame()\n",
    "for i,m in enumerate(models_remote):\n",
    "    \n",
    "    model_params=utils.get_model_params(m)\n",
    "    val_loss=utils.get_latest_loss(m,\"val\")\n",
    "\n",
    "\n",
    "#     if model_params[\"TRAIN\"][\"EPOCH_COUNT\"]-1==utils.get_latest_epoch_index(m):\n",
    "    raw_experiment_params=raw_experiment_params.append(model_params[\"TRAIN\"],ignore_index=True) \n",
    "    raw_experiment_data=raw_experiment_data.append(pd.Series([val_loss.mean()]),ignore_index=True)\n",
    "        \n",
    "    \n",
    "raw_experiment_data=raw_experiment_data.round(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# fix table\n",
    "experiments=pd.DataFrame()\n",
    "experiments[\"OPTIMIZER\"]=raw_experiment_params[\"OPTIMIZER\"].fillna(\"SGD\")\n",
    "experiments[\"LEARN RATE\"] = raw_experiment_params[\"ADAM_LEARN_RATE\"]\n",
    "experiments[\"LEARN RATE\"].fillna(raw_experiment_params[\"GD_LEARN_RATE\"],inplace=True)\n",
    "experiments[\"LEARN RATE\"].fillna(raw_experiment_params[\"LEARN_RATE\"],inplace=True)\n",
    "experiments[\"NETWORK TYPE\"]=raw_experiment_params[\"ENCODER_MODE\"]+\"-\"+raw_experiment_params[\"RNN_MODE\"]+\"-\"+raw_experiment_params[\"DECODER_MODE\"]\n",
    "experiments[\"BATCH SIZE\"]=raw_experiment_params[\"BATCH_SIZE\"]\n",
    "# experiments[\"EPOCH SIZE\"]=raw_experiment_params[\"EPOCH_COUNT\"]\n",
    "raw_experiment_data.columns=[\"MEAN VAL LOSS\"]\n",
    "experiments=pd.concat([experiments,raw_experiment_data],axis=1)\n",
    "experiments.to_csv(\"experiments.csv\",index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OPTIMIZER</th>\n",
       "      <th>LEARN RATE</th>\n",
       "      <th>NETWORK TYPE</th>\n",
       "      <th>BATCH SIZE</th>\n",
       "      <th>MEAN VAL LOSS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SGD</td>\n",
       "      <td>0.10000</td>\n",
       "      <td>SIMPLE-GRU-SIMPLE</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SGD</td>\n",
       "      <td>0.10000</td>\n",
       "      <td>SIMPLE-GRU-SIMPLE</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SGD</td>\n",
       "      <td>0.10000</td>\n",
       "      <td>SIMPLE-GRU-SIMPLE</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SGD</td>\n",
       "      <td>0.10000</td>\n",
       "      <td>SIMPLE-GRU-SIMPLE</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.098</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ADAM</td>\n",
       "      <td>0.00010</td>\n",
       "      <td>SIMPLE-GRU-SIMPLE</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>SGD</td>\n",
       "      <td>0.10000</td>\n",
       "      <td>SIMPLE-GRU-SIMPLE</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>SGD</td>\n",
       "      <td>0.10000</td>\n",
       "      <td>SIMPLE-GRU-SIMPLE</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>ADAM</td>\n",
       "      <td>0.00001</td>\n",
       "      <td>RESIDUAL-GRU-RESIDUAL</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>ADAM</td>\n",
       "      <td>0.00001</td>\n",
       "      <td>DILATED-GRU-DILATED</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0.169</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>ADAM</td>\n",
       "      <td>0.00001</td>\n",
       "      <td>RESIDUAL-GRU-RESIDUAL</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ADAM</td>\n",
       "      <td>0.00001</td>\n",
       "      <td>RESIDUAL-LSTM-RESIDUAL</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.175</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   OPTIMIZER  LEARN RATE            NETWORK TYPE  BATCH SIZE  MEAN VAL LOSS\n",
       "0        SGD     0.10000       SIMPLE-GRU-SIMPLE        16.0          0.185\n",
       "1        SGD     0.10000       SIMPLE-GRU-SIMPLE        16.0          0.112\n",
       "2        SGD     0.10000       SIMPLE-GRU-SIMPLE        16.0          0.155\n",
       "3        SGD     0.10000       SIMPLE-GRU-SIMPLE        16.0          0.098\n",
       "4       ADAM     0.00010       SIMPLE-GRU-SIMPLE        16.0          0.112\n",
       "5        SGD     0.10000       SIMPLE-GRU-SIMPLE        16.0          0.124\n",
       "6        SGD     0.10000       SIMPLE-GRU-SIMPLE        16.0          0.139\n",
       "7       ADAM     0.00001   RESIDUAL-GRU-RESIDUAL         8.0          0.153\n",
       "8       ADAM     0.00001     DILATED-GRU-DILATED        16.0          0.169\n",
       "9       ADAM     0.00001   RESIDUAL-GRU-RESIDUAL         8.0          0.121\n",
       "10      ADAM     0.00001  RESIDUAL-LSTM-RESIDUAL         8.0          0.175"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "experiments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "utils.fix_nparray(utils.get_latest_epoch(models_remote[6])+\"/train_loss.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_dir=params[\"SESSIONS\"][\"LONGEST\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "net=network.Network_restored(model_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ls=net.get_operations()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i,l in enumerate(ls):\n",
    "    if \"clip\" in l.name:\n",
    "        try:\n",
    "            print(len(l.inputs[0].shape))\n",
    "        except:\n",
    "            print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x,y=dataset.load_random_sample()\n",
    "vis.multichannel(x[0])\n",
    "out=net.predict(x)\n",
    "vis.voxel(out[0,:,:,:,0],out[0,:,:,:,1],f_name=\"test.png\")\n",
    "vis.voxel_binary(out[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ims=dataset.load_imgs_from_dir(\"data/demo_imgs\")\n",
    "ims=np.expand_dims(np.pad(ims,((0,0),(5,5),(5,5),(1,0)),\"constant\"),0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "for angle in range(0, 360,30):\n",
    "    vis.voxel_binary(out[0],view=(30,angle))\n",
    "    plt.pause(.001)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "op_list=net.get_operations()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for o in op_list:\n",
    "    print(o.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f=utils.list_folders(\"./models_remote\")[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p=glob.glob(f+\"/val/event*\")[0]\n",
    "p\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in tf.train.summary_iterator(p):\n",
    "    print(i)\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=tf.random_uniform([4,4])\n",
    "a_1=tf.pad(a,[[0,0],[0,0]])\n",
    "b=tf.random_uniform([8,8])\n",
    "c=tf.random_uniform([16,16])\n",
    "d=tf.random_uniform([32,32])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(a_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "params=utils.read_params()\n",
    "out_dir=params[\"DIRS\"][\"OUTPUT\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "clip=ImageSequenceClip(dataset.construct_file_path_list_from_dir(\"/Users/micmelesse/Documents/3D-reconstruction-with-neural-networks/output/02691156_131db4a650873babad3ab188d086d4db\",\".png\"),fps=12)\n",
    "clip.write_videofile(\"{}/movie.mp4\".format(out_dir))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "epoch_dir=\"models_remote/model_2018-04-02_20:10:12_L:0.1_E:40_B:16/epoch_0\"\n",
    "model_dir=os.path.dirname(epoch_dir)\n",
    "X_test,y_test=dataset.load_testset(epoch_dir)\n",
    "model_info = utils.get_model_info(model_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x,y=dataset.load_random_sample()\n",
    "vis.sample(x,y,y,\"test.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.imshow(ax.get_array())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ax.write_png(\"test.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vis.get_pylab_image(ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x,y=dataset.load_obj_id(\"02691156_131db4a650873babad3ab188d086d4db\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vis.sample(x,y,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"02691156_131db4a650873babad3ab188d086d4db\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "vis.voxel_binary(yp[0],\"frame_{}\".format(i))\n",
    "image_list=utils.filter_files(\"frame*.png\")\n",
    "print(image_list)\n",
    "clip=ImageSequenceClip(image_list,fps=6)\n",
    "clip.write_videofile(\"movie.mp4\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "loss_paths = dataset.construct_file_path_list_from_dir(\"aws\", \"loss.npy\")\n",
    "for path in loss_paths:\n",
    "    print(path)\n",
    "    print(utils.grep_learning_rate(path))\n",
    "    loss_arr = np.load(path)\n",
    "    print(loss_arr.shape)\n",
    "    plt.plot(loss_arr.flat)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p=np.load(\"voxel_prediction.npy\")\n",
    "p=np.transpose(p,[0,1,3,4,2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vp=np.load(\"voxel_prediction.npy\")[23]\n",
    "vp=np.transpose(vp,[0,2,3,1])\n",
    "vis.voxel_b(vp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vis.voxel_binary(yp[0])\n",
    "plt.figure()\n",
    "plt.imshow(vis.voxel_ndarray(yp[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights=np.load(\"/Users/micmelesse/Documents/3D-reconstruction-with-neural-networks/data/ResidualGRUNet.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "l=utils.list_folders(\"aws\")[-1]\n",
    "png_ls=dataset.construct_file_path_list_from_dir(\"aws/model_2018-04-02_20:10:12_L:0.1_E:40_B:16\", \"_p.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "png_ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for f in png_ls:\n",
    "    obj_id=utils.grep_obj_id(f)\n",
    "    n=utils.grep_stepcount(f)\n",
    "    new_name=os.path.dirname(f)+\"/\"+n+'_'+obj_id+'_yp.png'\n",
    "#     print(f,new_name)\n",
    "    os.rename(f,new_name)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "png_ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Image.open(png_ls[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "utils.grep_obj_id(\"uiudasniuansfuas_asnfasnfkasfunkasufn_x.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# toy example\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "LEARNING_RATE, EPOCHS=0.01,100                              # hyper paramters\n",
    "\n",
    "# Build Tensorflow Graph\n",
    "X = tf.constant([[1],[2],[3]],dtype=tf.float32)             # input\n",
    "W = tf.Variable(tf.random_uniform([3,3]),dtype=tf.float32)  # paramters\n",
    "Y = tf.matmul(W,X)                                          # prediction\n",
    "T = tf.constant([[3],[2],[1]],dtype=tf.float32)             # target label\n",
    "E = tf.reduce_mean(tf.abs(T-Y))                             # Error \n",
    "GD=tf.train.GradientDescentOptimizer(LEARNING_RATE)         # optimizing algorihtm\n",
    "Gradients = GD.compute_gradients(E)                         # compute the gradients from the Error\n",
    "TRAIN_STEP = GD.apply_gradients(Gradients)                  # use the gradients to update their paramters\n",
    "\n",
    "\n",
    "# Run Graph\n",
    "with tf.Session() as sess:                                  # start tensorflow session\n",
    "    tf.global_variables_initializer().run()                 # initialize variables\n",
    "    for i in range(EPOCHS):                                 # open pass over the dataset\n",
    "        result=sess.run([E,Y,TRAIN_STEP])                   # fetch values from tensorflow graph\n",
    "        \n",
    "print(result[0]) \n",
    "print(result[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "kernel=tf.random_uniform([3,3,10,10])\n",
    "print(kernel)\n",
    "\n",
    "kern_1 = tf.concat(tf.unstack(kernel, axis=-1), axis=-1)\n",
    "kern_2 = tf.transpose(kern_1, [2,0,1])\n",
    "kern_3 = tf.expand_dims(kern_2, -1)\n",
    "\n",
    "print(kern_1)\n",
    "print(kern_2)\n",
    "print(kern_3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ret=tf.random_uniform([36,5,127,127,3])\n",
    "print(ret)\n",
    "\n",
    "feature_map_1 = tf.concat(tf.unstack(ret, axis=4), axis=2)\n",
    "feature_map_2 = tf.concat(tf.unstack(feature_map_1, axis=1), axis=2)\n",
    "feature_map_3 = tf.expand_dims(feature_map_2, -1)\n",
    "\n",
    "print(feature_map_1)\n",
    "print(feature_map_2)\n",
    "print(feature_map_3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "kernel=tf.random_uniform([3,3,3,10,10])\n",
    "print(kernel)\n",
    "\n",
    "kern_1 = tf.concat(tf.unstack(kernel, axis=-1), axis=-1)\n",
    "kern_2 = tf.transpose(kern_1,[3,0,1,2])\n",
    "kern_3 = tf.expand_dims(kern_2,-1)\n",
    "kern_4 = tf.concat(tf.unstack(kern_3, axis=1), axis=1)\n",
    "\n",
    "print(kern_1)\n",
    "print(kern_2)\n",
    "print(kern_3)\n",
    "print(kern_4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ret=tf.random_uniform([2,32,32,32,2])\n",
    "print(ret)\n",
    "\n",
    "vox_slice_1 = tf.unstack(ret, axis=4)[1]\n",
    "vox_slice_2 = tf.split(vox_slice_1,4, axis=3)\n",
    "vox_slice_3 = tf.concat(vox_slice_2, axis=2)\n",
    "vox_slice_4 = tf.concat(tf.unstack(vox_slice_3,axis=-1),axis=1)\n",
    "vox_slice_5 = tf.expand_dims(vox_slice_4,-1)\n",
    "\n",
    "print(vox_slice_1)\n",
    "print(vox_slice_2)\n",
    "print(vox_slice_3)\n",
    "print(vox_slice_4)\n",
    "print(vox_slice_5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "LEARNING_RATE, EPOCHS = 0.01,100                     # hyper-parameters\n",
    "\n",
    "# Build Tensorflow Graph\n",
    "X = tf.constant([[1.0],[2.0],[3.0]])                 # input\n",
    "T = tf.constant([[3.0],[2.0],[1.0]])                 # target\n",
    "W = tf.Variable(tf.random_uniform([3,3]))            # parameters\n",
    "Y = tf.matmul(W,X)                                   # prediction\n",
    "L = tf.reduce_mean(tf.abs(T-Y))                      # loss(error)\n",
    "\n",
    "GD = tf.train.GradientDescentOptimizer(LEARNING_RATE)# optimizing algorithm\n",
    "Gradients = GD.compute_gradients(L)                  # gradient of the error function\n",
    "TRAIN_STEP = GD.apply_gradients(Gradients)           # update parameters using gradients\n",
    "\n",
    "# Run Graph\n",
    "with tf.Session() as sess:                           # start tensorflow session\n",
    "    tf.global_variables_initializer().run()          # initialize variables\n",
    "    for i in range(EPOCHS):                          # iterate over the dataset EPOCHS times\n",
    "        result=sess.run([L,Y,TRAIN_STEP])            # fetch values from graph\n",
    "        \n",
    "print(\"Loss:\", result[0]) \n",
    "print(\"Prediction:\", result[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
